package com.algrithom.stropr;

/**
 * 848. 字母移位
 * 
 * @author think
 */
public class Solution4 {
    
    public static void main(String[] args){
        String str = "abc";
        int[] shifts = new int[]{3,5,9};
        Solution4 solution4 = new Solution4();
        System.out.println(solution4.shiftingLetters(str,shifts));
    }
    
    public String shiftingLetters(String S,int[] shifts){
        StringBuilder ans = new StringBuilder();
        int X = 0;
        for (int shift : shifts) {
            X = (X + shift) % 26;
        }
        
        for (int i = 0; i < S.length(); ++i) {
            int index = S.charAt(i) - 'a';
            ans.append((char)((index + X) % 26 + 97));
            X = Math.floorMod(X - shifts[i],26);
        }
        
        return ans.toString();
    }
}